package com.duowei.diandan.db.dao;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;

import com.duowei.diandan.db.entry.Dmpzsd;

import java.util.List;

@Dao
public interface DmpzsdDao {

    @Query("SELECT dmpzsd.* " +
            "FROM dmpzsd LEFT JOIN dmkwdydp ON dmpzsd.pzbm = dmkwdydp.pzbm WHERE dmkwdydp.xmbh = :xmbh ORDER BY pxh")
    List<Dmpzsd> findByDmkwdydpXmbh(String xmbh);

    @Query("SELECT * FROM dmpzsd")
    List<Dmpzsd> findAll();

    @Query("SELECT * " +
            "FROM dmpzsd " +
            "WHERE pzbm IN (SELECT pzbm FROM dmkwdydp WHERE xmbh = :xmbh )")
    LiveData<List<Dmpzsd>> findByXmbh(String xmbh);

    @Query("SELECT * FROM dmpzsd WHERE dycp LIKE :xmbh LIMIT 1")
    Dmpzsd findByDycpLike(String xmbh);

    @Insert
    void insert(List<Dmpzsd> list);

    @Query("DELETE FROM dmpzsd")
    void deleteAll();
}
